/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	ANoticeServiceImpl.java
 * Created：		2016年9月11日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.notice;

import org.springframework.beans.factory.annotation.Autowired;

import com.thor.commons.exception.ThorServiceException;
import com.thor.commons.query.QueryResult;
import com.thor.commons.util.Assert;
import com.thor.palmmall.rest.notice.converter.ANoticeConverter;
import com.thor.palmmall.rest.notice.converter.ANoticeConverter2;
import com.thor.palmmall.rest.notice.converter.SNoticeParamConverter;
import com.thor.palmmall.rest.notice.converter.SNoticeParamConverter2;
import com.thor.palmmall.spi.common.SQueryResult;
import com.thor.palmmall.spi.common.SQueryResultConverter;
import com.thor.palmmall.spi.common.SResponse;
import com.thor.palmmall.spi.notice.SNotice;
import com.thor.palmmall.spi.notice.SNotice2;
import com.thor.palmmall.spi.notice.SNoticeService;

/**
 * @author wolv
 *
 */
public class ANoticeServiceImpl implements ANoticeService {

  @Override
  public QueryResult<ANotice> query(ANoticeParam param) throws ThorServiceException {
    Assert.assertArgumentNotNull(param, "param");

    SResponse<SQueryResult<SNotice>> resp = sNoticeService
        .query(SNoticeParamConverter.getInstance().convert(param));
    if (resp.isSuccess())
      return SQueryResultConverter.convert(resp.getBody(), ANoticeConverter.getInstance());
    else
      throw new ThorServiceException("无法查询公告：" + resp.getMessage());

  }

  @Override
  public ANotice get(String uuid) throws ThorServiceException {
    SResponse<SNotice> resp = sNoticeService.get(uuid);
    if (resp.isSuccess())
      return ANoticeConverter.getInstance().convert(resp.getBody());
    else
      throw new ThorServiceException("无法找到指定ID的公告：" + resp.getMessage());
  }

  @Override
  public QueryResult<ANotice2> query2(ANoticeParam param) throws ThorServiceException {
    Assert.assertArgumentNotNull(param, "param");

    SResponse<SQueryResult<SNotice2>> resp = sNoticeService
        .query2(SNoticeParamConverter.getInstance().convert(param));
    if (resp.isSuccess())
      return SQueryResultConverter.convert(resp.getBody(), ANoticeConverter2.getInstance());
    else
      throw new ThorServiceException("无法查询公告：" + resp.getMessage());

  }

  @Override
  public ANotice2 get2(ANoticeParam2 param) throws ThorServiceException {
    Assert.assertArgumentNotNull(param, "param");

    SResponse<SNotice2> resp = sNoticeService
        .get2(SNoticeParamConverter2.getInstance().convert(param));
    if (resp.isSuccess())
      return ANoticeConverter2.getInstance().convert(resp.getBody());
    else
      throw new ThorServiceException("无法找到指定ID的公告：" + resp.getMessage());

  }

  @Autowired
  private SNoticeService sNoticeService;
}
